home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
By the Book
/
Learn C++ (CodeWarrior)
/
Chap 06.03 - square
/
square.cp
< prev
next >
Wrap
Text File
|
1995-10-20
|
964b
|
62 lines
#include <iostream.h>
//--------------------------------------- Rectangle
class Rectangle
{
// Data members...
protected:
short height;
short width;
// Member functions...
public:
Rectangle( short heightParam, short widthParam );
void DisplayArea();
};
Rectangle::Rectangle( short heightParam, short widthParam )
{
height = heightParam;
width = widthParam;
}
void Rectangle::DisplayArea()
{
cout << "Area is: " <<
height * width << '\n';
}
//--------------------------------------- Rectangle:Square
class Square : public Rectangle
{
// Data members...
// Member functions...
public:
Square( short side );
};
Square::Square( short side ) : Rectangle( side, side )
{
}
//--------------------------------------- main()
int main()
{
Square *mySquare;
Rectangle *myRectangle;
mySquare = new Square( 10 );
mySquare->DisplayArea();
myRectangle = new Rectangle( 10, 15 );
myRectangle->DisplayArea();
return 0;
}